#include <bits/stdc++.h>
#define fi first
#define se second
using ll=long long;
using namespace std;
const int N = 1e6 + 10;
int a[N], s[N];
void solve()
{
    int n, k1 = 0,k2 = 0;
    cin >> n;
    for (int i = 1; i <= n;i++)
    {
        cin >> a[i];
        if(a[i]==1&&k1==0)
            k1 = i;
        if(a[i]==1)
            k2 = i;
        s[i] = s[i - 1] + a[i];
    }
    int ans = 0;
    for (int l = 1; l <= k2;l++)
    {
        for (int r = k1; r <= n;r++)
        {
            if(s[r]-s[l-1]==1)
                ans++;
        }
    }
    cout << ans;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    int T = 1;
    // cin>>T;
    while (T--)
    {
        solve();
    }
    return 0;
}